package com.youku.plugins.commonui.view
{
   import flash.display.Sprite;
   import com.youku.interfaces.ISkinChangeCompent;
   import com.youku.baseUI.BasePlayerButton;
   import flash.display.MovieClip;
   import flash.text.TextField;
   import flash.utils.Timer;
   import com.youku.utils.DrawUtil;
   import com.youku.utils.AssetUtil;
   import flash.text.TextFormat;
   import com.youku.skin.YaheiFontManager;
   import flash.text.TextFieldAutoSize;
   import flash.events.TimerEvent;
   import flash.events.MouseEvent;
   import com.youku.skin.PartenerSkinManager;
   import flash.events.Event;
   import com.youku.plugins.commonui.CommonUIEvent;
   import com.youku.utils.ScreenOutput;
   import flash.utils.getTimer;
   import flash.ui.Mouse;
   import com.youku.utils.BaseUtil;
   import com.youku.PlayerConfig;
   
   public class VideoOverLayer extends Sprite implements ISkinChangeCompent
   {
      
      public function VideoOverLayer() {
         super();
         this.init();
      }
      
      private var _layer:Sprite;
      
      private var _closeButton:BasePlayerButton;
      
      private var _loadingLayer:Sprite;
      
      private var _loadingBg:MovieClip;
      
      private var _loading:MovieClip;
      
      private var _loadingText:TextField;
      
      private var _width:Number;
      
      private var _height:Number;
      
      private var _enable:Boolean;
      
      private var _fullscreen:Boolean;
      
      private var _lastClickTime:Number;
      
      private var _doubleClickTimer:Timer;
      
      private var _seekTime:SeekTimeDisplayer;
      
      private var _v4:Boolean;
      
      private function init() : void {
         this._lastClickTime = 0;
         this._layer = DrawUtil.RectangleSprite(0,0,100,100,0,0,null,0);
         this._closeButton = AssetUtil.getStyleButton("C_Full_Screen_close");
         AssetUtil.restoreButtonSize(this._closeButton);
         this._loadingLayer = new Sprite();
         this._loadingBg = AssetUtil.getAsset("Loading_BG_V4") as MovieClip;
         this._loadingBg.alpha = 0.9;
         this._loadingLayer.addChild(this._loadingBg);
         this._loading = AssetUtil.getAsset("Loading_Ring") as MovieClip;
         this._loading.width = 32;
         this._loading.height = 32;
         this._loading.x = 22;
         this._loading.y = 13;
         this._loadingLayer.addChild(this._loading);
         this._loadingText = AssetUtil.getTextField(false);
         this._loadingText.defaultTextFormat = new TextFormat(YaheiFontManager.MICROSOFT_YAHEI,14,15658734);
         this._loadingText.autoSize = TextFieldAutoSize.LEFT;
         this._loadingText.text = "加载中...";
         this._loadingText.x = 14;
         this._loadingText.y = 45;
         this._loadingLayer.addChild(this._loadingText);
         this._seekTime = new SeekTimeDisplayer();
         addChild(this._layer);
         addChild(this._loadingLayer);
         addChild(this._closeButton);
         addChild(this._seekTime);
         this._localConnectID = new TextField();
         this._localConnectID.width = 120;
         this._localConnectID.height = 25;
         this._localConnectID.defaultTextFormat = new TextFormat(YaheiFontManager.MICROSOFT_YAHEI,14,15658734);
         this._localConnectID.x = 10;
         this._localConnectID.y = 20;
         this._localConnectID.visible = false;
         this._localConnectID.border = true;
         addChild(this._localConnectID);
         this._closeButton.visible = false;
         this._loadingLayer.visible = false;
         this._doubleClickTimer = new Timer(300);
         this._doubleClickTimer.addEventListener(TimerEvent.TIMER,this.onTimer);
         this._layer.addEventListener(MouseEvent.CLICK,this.onLayerClick);
         this._closeButton.addEventListener(MouseEvent.CLICK,this.onCloseButtonClick);
         this._enable = false;
         this._fullscreen = false;
         PartenerSkinManager.push(this);
      }
      
      private function onWaterMarkLoaded(param1:Event) : void {
         this.updateLayout();
      }
      
      private function onCloseButtonClick(param1:MouseEvent) : void {
         dispatchEvent(new CommonUIEvent(CommonUIEvent.VIDEO_LAYER_CLOSE_FULLSCREEN));
      }
      
      private function onLayerClick(param1:MouseEvent) : void {
         ScreenOutput.log("videooverlayer.onlayerclick: " + [getTimer(),param1.target]);
         var _loc2_:Number = getTimer();
         if(_loc2_ - this._lastClickTime < 300)
         {
            dispatchEvent(new CommonUIEvent(CommonUIEvent.VIDEO_LAYER_DOUBLECLICK));
            this._doubleClickTimer.stop();
         }
         else
         {
            this._doubleClickTimer.reset();
            this._doubleClickTimer.start();
         }
         this._lastClickTime = _loc2_;
      }
      
      private function onTimer(param1:TimerEvent) : void {
         this._doubleClickTimer.stop();
         dispatchEvent(new CommonUIEvent(CommonUIEvent.VIDEO_LAYER_CLICK));
      }
      
      public function toggleFullScreen(param1:Boolean) : void {
         this._fullscreen = param1;
         if(!param1)
         {
            this._closeButton.visible = false;
            Mouse.show();
         }
      }
      
      public function setSize(param1:Number, param2:Number) : void {
         this._width = param1;
         this._height = param2;
         this._layer.width = param1;
         this._layer.height = param2;
         this.updateLayout();
      }
      
      private function updateLayout() : void {
         this._layer.x = 0;
         this._layer.y = 0;
         this._closeButton.x = this._layer.x + this._layer.width - this._closeButton.width - 3;
         this._closeButton.y = 3;
         this._loadingLayer.x = (this._width - 76) / 2;
         this._loadingLayer.y = (this._height - 76) / 2;
         if(this._width > 930)
         {
            this._loadingLayer.scaleX = this._loadingLayer.scaleY = this._width / 930;
         }
         else
         {
            this._loadingLayer.scaleX = this._loadingLayer.scaleY = 1;
         }
         this._seekTime.x = this._seekTime.y = 50;
         if(this._width > 930)
         {
            this._seekTime.scaleX = this._seekTime.scaleY = this._width / 930;
         }
         else
         {
            this._seekTime.scaleX = this._seekTime.scaleY = 1;
         }
         if(this._width < 440)
         {
            this._seekTime.visible = false;
         }
         else
         {
            this._seekTime.visible = true;
         }
      }
      
      public function get enable() : Boolean {
         return this._enable;
      }
      
      public function set enable(param1:Boolean) : void {
         this._enable = param1;
         if(this._enable)
         {
            this._layer.addEventListener(MouseEvent.CLICK,this.onLayerClick);
            if(!this._v4)
            {
               this._layer.useHandCursor = true;
               this._layer.buttonMode = true;
            }
         }
         else
         {
            this._layer.removeEventListener(MouseEvent.CLICK,this.onLayerClick);
            if(!this._v4)
            {
               this._layer.useHandCursor = false;
               this._layer.buttonMode = false;
            }
         }
      }
      
      public function showCloseButton(param1:Boolean) : void {
         if(this._fullscreen)
         {
            if(param1)
            {
               Mouse.show();
            }
            else
            {
               Mouse.hide();
            }
         }
      }
      
      public function showLoading(param1:Boolean) : void {
         if(param1)
         {
            this.addChild(this._loadingLayer);
         }
         else if(this.contains(this._loadingLayer))
         {
            this.removeChild(this._loadingLayer);
         }
         
         this._loadingLayer.visible = param1;
      }
      
      public function setLoadingPercent(param1:Number) : void {
         if(param1 >= 1)
         {
            this.showLoading(false);
         }
         var _loc2_:String = String(int(param1 * 100));
         this._loadingText.text = "加载中...";
         this.updateLayout();
      }
      
      public function showSeekTime(param1:Number, param2:Number) : void {
         var _loc3_:String = BaseUtil.formatTime(param1);
         _loc3_ = _loc3_ + (" (" + String(Math.round(param1 / param2 * 100)) + "%)");
         this._seekTime.show(_loc3_);
      }
      
      public function upDateSkin() : void {
         if(PlayerConfig.rootData.styleid < 2)
         {
            return;
         }
         if(PlayerConfig.partnerData.skinData.status == 0 || !PlayerConfig.partnerData.skinData.isSetupDiv)
         {
            return;
         }
         this._loading.filters = PartenerSkinManager.getFilters(PartenerSkinManager.LOADING);
      }
      
      public function clearSkin() : void {
         this._loading.filters = [];
      }
      
      private var _localConnectID:TextField;
      
      private var _isLocalConnectShowing:Boolean;
      
      public function showLocalConnectID(param1:String) : void {
         this._localConnectID.text = param1;
         if(this._isLocalConnectShowing)
         {
            this._localConnectID.visible = false;
            this._isLocalConnectShowing = false;
         }
         else
         {
            this._localConnectID.visible = true;
            this._isLocalConnectShowing = true;
         }
      }
   }
}
import flash.display.Sprite;
import flash.text.TextField;
import flash.utils.Timer;
import com.youku.utils.Tweener;
import flash.events.TimerEvent;
import flash.text.TextFormat;
import flash.filters.DropShadowFilter;

class SeekTimeDisplayer extends Sprite
{
   
   function SeekTimeDisplayer() {
      super();
      this._textField = new TextField();
      this._textField.defaultTextFormat = new TextFormat("Arial",18,15790320);
      this._textField.selectable = false;
      this._textField.width = 140;
      this._textField.height = 24;
      this._textField.cacheAsBitmap = true;
      this._textField.filters = [new DropShadowFilter(0,0,0,0.5,4,4)];
      this._textField.alpha = 0;
      addChild(this._textField);
      this._timer = new Timer(this._interval,1);
      this._timer.addEventListener(TimerEvent.TIMER_COMPLETE,this.onTimeout);
      this.mouseEnabled = false;
   }
   
   private var _textField:TextField;
   
   private var _tweenSpeed:Number = 0.5;
   
   private var _timer:Timer;
   
   private var _interval:Number = 2000.0;
   
   public function show(param1:String) : void {
      Tweener.to(this._textField,this._tweenSpeed,{"alpha":1});
      this._textField.text = param1;
      this._timer.reset();
      this._timer.start();
   }
   
   private function onTimeout(param1:TimerEvent) : void {
      this.hide();
   }
   
   private function hide() : void {
      Tweener.to(this._textField,this._tweenSpeed,{"alpha":0});
   }
}
